package kr.hkit.androidcomplete03.ch23;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class AnimationTest extends Activity {
	ImageView mImageTarget;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_animationtest);
		mImageTarget = (ImageView) findViewById(R.id.ch23_anitest_animtarget);
	}
	
	public void mOnClick(View v){
		Animation ani = null;
		switch (v.getId()) {
		case R.id.ch23_anitest_btntrans1:
				ani = new TranslateAnimation(0, 200, 0, 0);
			break;
		case R.id.ch23_anitest_btntrans2:
			ani = new TranslateAnimation(
					Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
					Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
			break;
		case R.id.ch23_anitest_btntrans3:
			ani = new TranslateAnimation(
					Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 1,
					Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
			break;
		case R.id.ch23_anitest_btnrotate1:
			ani = new RotateAnimation(0, -100);
			break;
		case R.id.ch23_anitest_btnrotate2:
			ani = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 1f,
					Animation.RELATIVE_TO_SELF, 1f);
			break;
		case R.id.ch23_anitest_btnrotate3:
			ani = new RotateAnimation(0, -90, Animation.RELATIVE_TO_PARENT, 0.5f,
					Animation.RELATIVE_TO_PARENT, 1.0f);
			break;
		case R.id.ch23_anitest_btnscale1:
			ani = new ScaleAnimation(0, 1, 0, 1);
			break;
		case R.id.ch23_anitest_btnscale2:
			ani = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
			break;
		case R.id.ch23_anitest_btnscale3:
			ani = new ScaleAnimation(1, 0, 1, 0, Animation.RELATIVE_TO_SELF, 0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
			break;
		case R.id.ch23_anitest_btnalpha1:
			ani = new AlphaAnimation(0, 1);
			break;
		case R.id.ch23_anitest_btnalpha2:
			ani = new AlphaAnimation(1,0);
			break;
		}
		ani.setDuration(500);
		mImageTarget.startAnimation(ani);
	}
}
